<template>
  <div class="app-container">
    <el-card>
      <div slot="header">
        <span>预约金设置</span>
      </div>
      <el-form :inline="true"
               class="demo-form-inline">
        <el-form-item label="预约金的代码">

          <el-input v-model="card"
                    placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="备注">

          <el-input v-model="description"
                    placeholder="请输入"></el-input>
        </el-form-item>
        <el-button type="primary"
                   size="small"
                   @click="setCard">修改</el-button>

      </el-form>
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getRvt, setCard } from '@/api/yue'
export default {
  name: 'Profile',
  data () {
    return {
      card: "",
      id: "",
      description: ""
    }
  },
  filters: {
    getTime (timestamp) {
      var time = new Date(timestamp);
      var y = time.getFullYear(); //getFullYear方法以四位数字返回年份
      var M = time.getMonth() + 1; // getMonth方法从 Date 对象返回月份 (0 ~ 11)，返回结果需要手动加一
      M = m < 10 ? "0" + M : M;
      var d = time.getDate(); // getDate方法从 Date 对象返回一个月中的某一天 (1 ~ 31)
      d = d < 10 ? "0" + d : d;
      var h = time.getHours(); // getHours方法返回 Date 对象的小时 (0 ~ 23)
      h = h < 10 ? "0" + h : h;
      var m = time.getMinutes(); // getMinutes方法返回 Date 对象的分钟 (0 ~ 59)
      m = m < 10 ? "0" + m : m;
      var s = time.getSeconds(); // getSeconds方法返回 Date 对象的秒数 (0 ~ 59)
      s = s < 10 ? "0" + s : s;
      return y + "-" + M + "-" + d + " " + h + ":" + m + ":" + s;
    }
  },
  created () {
    this.getData()
  },
  methods: {
    reset () {
      this.name = '';
      this.startTime = '';
      this.endTime = "";
      this.getData();
    },
    getData () {
      getRvt().then(res => {
        this.card = res.data.card;
        this.id = res.data.id
        this.description = res.data.description
      })
    },
    handleSearch () {
      this.getData();
    },
    handleSizeChange (val) {
      this.pageSize = val;
      this.getData();

    },
    setCard () {
      if (this.card == '') {
        return this.$message({
          message: '请填写预约金设置',
          type: "warning"
        })
      }
      setCard(this.card).then(res => {
        if (res.code == 200) {
          this.$message({
            message: "设置成功",
            type: "success"
          })
        } else {
          this.$message({
            message: res.message,
            type: "warning"
          })
        }
      })
    },
    handleCurrentChange (val) {
      this.page = val;
      this.getData();
    }
  }
}
</script>
